package com.itheima.controller;

import com.itheima.common.ProfileResult;
import com.itheima.common.R;
import com.itheima.service.FrameService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/*
 *@Parm
 *@ClassName FrameController
 *@Date 2022/1/11 20:13
 */
@RestController
@RequestMapping("/frame")
public class FrameController {

    @Autowired
    private HttpServletRequest request;

    @Autowired
    private FrameService userService;


    @PostMapping("/register")
    public R register(String username, String password){
        return userService.regist(username,password);
    }


    @PostMapping("/profile")
    public ProfileResult profiles(){

        return userService.profile();
    }

    @PostMapping("/logout")
    public void logout(){
        HttpSession session = request.getSession();
        session.removeAttribute("token");
    }

    @PostMapping("/login")
    public R login(String username,String password) {
        R r = userService.login(username,password);
        return r;
    }

    @PostMapping("/password")
    public R updatePassword(String oldPassword,String newPassword){
        return userService.updatePassword(oldPassword,newPassword);
    }

}
